//
//  PKTopicCommentCell.m
//  PianKe
//
//  Created by lanou on 15/10/17.
//  Copyright (c) 2015年 李伟伟. All rights reserved.
//

#import "PKTopicCommentCell.h"
#import <UIImageView+WebCache.h>
@implementation PKTopicCommentCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 40, 40)];
        _iconView.layer.cornerRadius = 20;
        _iconView.layer.masksToBounds = YES;
        _iconView.contentMode = UIViewContentModeScaleAspectFit;
        
        _unameLabel = [[UILabel alloc]initWithFrame:CGRectMake(65, 10, 100, 20)];
        _unameLabel.font = [UIFont systemFontOfSize:16];
        
        _cmtnumLabel = [[UILabel alloc]initWithFrame:CGRectMake(65, 30, 50, 20)];
        _cmtnumLabel.font = [UIFont systemFontOfSize:12];
        
        _addtime_fLabel = [[UILabel alloc]initWithFrame:CGRectMake(115, 30, 100, 20)];
        _addtime_fLabel.font = [UIFont systemFontOfSize:12];
        
        _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 60, SCREEN_WITDTH-80, 50)];
        _contentLabel.font = [UIFont systemFontOfSize:14];
        _contentLabel.numberOfLines = 2;
        
        _likenumLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WITDTH-100, 10, 60, 20)];
        _likenumLabel.font = [UIFont systemFontOfSize:12];
        
        [self.contentView addSubview:_iconView];
        [self.contentView addSubview:_unameLabel];
        [self.contentView addSubview:_cmtnumLabel];
        [self.contentView addSubview:_addtime_fLabel];
        [self.contentView addSubview:_contentLabel];
        [self.contentView addSubview:_likenumLabel];
    }
    return self;
}

-(void)configureTopicCommentCell:(PKTopicCommentModel *)model
{
    [_iconView sd_setImageWithURL:[NSURL URLWithString:model.userinfo.icon]];
    _unameLabel.text = model.userinfo.uname;
    _cmtnumLabel.text = [NSString stringWithFormat:@"%ld楼 ·",model.cmtnum];
    _addtime_fLabel.text = model.addtime_f;
    _contentLabel.text = model.content;
    _likenumLabel.text = [NSString stringWithFormat:@"%ld",  model.likenum];
    _contentLabel.frame = CGRectMake(20, 60, SCREEN_WITDTH-80, [PKTopicCommentCell heightOfCommentString:model]);
    
    
}


+(CGFloat)heightOfCommentString:(PKTopicCommentModel *)model
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
    NSString *str = model.content;
    CGRect bounds = [str boundingRectWithSize:CGSizeMake(SCREEN_WITDTH-80, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return bounds.size.height;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
